package com.winning.ds.common.util;

import com.winning.ds.common.entity.MenuTreeEntity;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* @Author: nxs@winning.com.cn
*
* @Description:  递归构造树型结构
*
* @Date: 2018-07-06 14:06:45
*
*
 **/
    public class MenuTreeUtil {

        public List<MenuTreeEntity> menuCommon;
        public List<Object> list = new ArrayList<Object>();

        public List<Object> menuTreeList(List<MenuTreeEntity> menuList){
            this.menuCommon = menuList;
            for (MenuTreeEntity mte : menuList) {
                Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
               // if( null == mte.getPcode() || mte.getPcode().equals("")){
                if(mte==null){
                }
                if(StringUtils.isBlank(mte.getPcode())){
                    mapArr.put("id", mte.getMcode());
                    mapArr.put("name", mte.getMcaption());
                    mapArr.put("pId", mte.getPcode());
                    list.add(mapArr);
                    list.addAll(menuChild(mte.getMcode()));
                }
            }
            return list;
        }

        public List<?> menuChild(String munuid){
            List<Object> lists = new ArrayList<Object>();
            for(MenuTreeEntity a:menuCommon){
                Map<String,Object> childArray = new LinkedHashMap<String, Object>();
                if(munuid.equals(a.getPcode())){
                    childArray.put("id", a.getMcode());
                    childArray.put("name", a.getMcaption());
                    childArray.put("pId", a.getPcode());
                    lists.add(childArray);
                    lists.addAll(menuChild(a.getMcode()));
                }
            }
            return lists;
        }

 }









